package com.zonski.jbots.desktop.client.entity;

import com.zonski.jbots.desktop.client.EntityRenderer;
import com.zonski.jbots.engine.Entity;
import com.zonski.jbots.engine.Modes;

import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: Chris Glover
 * Date: Oct 13, 2003
 * Time: 10:48:41 AM
 * To change this template use Options | File Templates.
 */
public class EggRenderer implements EntityRenderer
{
    public EggRenderer()
    {
    }

    public void render(Graphics g, Entity entity)
    {
        // TODO : colors
        if(entity.getMode() == Modes.NONE)
        {
            Color startColor;
            Color endColor = Color.white;

            switch(entity.layerId)
            {
                case 1:
                    startColor = Color.red;
                    break;
                case 2:
                    startColor = Color.cyan;
                    break;
                case 3:
                    startColor = Color.magenta;
                    break;
                case 4:
                    startColor = Color.yellow;
                    break;
                default:
                    startColor = Color.gray;
                    break;
            }

            int dred = endColor.getRed() - startColor.getRed();
            int dgreen = endColor.getGreen() - startColor.getGreen();
            int dblue = endColor.getBlue() - startColor.getBlue();

            com.zonski.jbots.engine.Rectangle bounds = entity.bounds;
            int height = bounds.height;
            for(int h = height; h>0; h--)
            {
                int rd = startColor.getRed() + (dred * (height - h))/height;
                int gn = startColor.getGreen() + (dgreen * (height - h))/height;
                int bl = startColor.getBlue() + (dblue * (height - h))/height;
                g.setColor(new Color(rd, gn, bl));
                int w = (bounds.width * h)/bounds.height;
                g.fillOval(bounds.x + (bounds.width- w)/2,
                        bounds.y + (bounds.height - h)/2,
                        w, h);
            }
            g.setColor(Color.black);
            g.drawOval(bounds.x, bounds.y, bounds.width, bounds.height);
        }
    }
}
